package com.yanqu.road.server.cmd.activity.harps;

import com.yanqu.road.entity.activity.harps.HarpsConfigSync;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.harps.Harps;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.harps.HarpsModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.harps.HarpsMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_HARPS_PLAY, desc = "演奏")
public class HarpsPlayCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        Harps.HarpsPlayReq req = Harps.HarpsPlayReq.parseFrom(packet.getBytes());
        HarpsConfigSync config = HarpsMgr.getConfig();
        if (config == null || !player.getModule(HarpsModule.class).inActivityTime()) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }

        ret = player.getModule(HarpsModule.class).playCmd(req.getIsTenDraws());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }

        Harps.HarpsPlayResp.Builder respMsg = Harps.HarpsPlayResp.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_HARPS_PLAY, respMsg);
    }
}
